<!--
 * @Author: dfh
 * @Date: 2024-03-18 13:11:34
 * @LastEditors: dfh
 * @Modified By: dfh
 * @describe: 
-->
<template>
    <view class="container">
        <header-search></header-search>
        <scroll-view scroll-y class="scroll">
            <banner :data="articleList" :bankList="bankList"></banner>
            <active-board :bankList="bankList"></active-board>
            <board-view :data="bankRateList" :bankList="bankList"></board-view>
            <card-list :bankList="bankList"></card-list>
        </scroll-view>

    </view>
</template>

<script setup>
import HeaderSearch from './components/header-search.vue';
import Banner from './components/banner.vue';
import ActiveBoard from './components/active-board.vue';
import BoardView from './components/board-view.vue';
import CardList from './components/card-list.vue';
import { fetchBankList } from '@/services/bank'
import { fetchArticleList, fetchBankRateList } from '@/services/home'
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue'
import {showToast} from '@/utils/toast'

const articleList = ref([]);
const bankRateList = ref([]);
const bankList = ref([]);

onLoad(() => {
    getArticleList();
    getBankRateList();
    getBankList();
    wx.showShareMenu({
        withShareTicket: true,
        menus: ['shareAppMessage', 'shareTimeline']
    })
})

const getBankList = async () => {
    const { msg, status, data } = await fetchBankList();
    if (status === 1) {
        bankList.value = data || [];
    } else {
        showToast(msg || '获取银行卡列表失败')
    }
}

const getArticleList = async () => {
    const { msg, status, data } = await fetchArticleList();
    if (status === 1) {
        const { list } = data;
        articleList.value = list || [];
    } else {
        showToast(msg || '获取文章失败')
    }
}

const getBankRateList = async () => {
    const { msg, status, data } = await fetchBankRateList();
    if (status === 1) {
        const list = (data || []).reduce((m, o) => {
            const bankRateReps = o.bankRateReps.filter(item => (item.saveDate == '一个月' || item.saveDate == '三个月' || item.saveDate == '六个月'))
            m.push({ ...o, bankRateReps })
            return m;
        }, [])
        bankRateList.value = list;
    } else {
        showToast(msg || '获取失败')
    }
}


</script>

<style lang="scss" scoped>
.container {
    position: absolute;
    width: 100vw;
    height: 100vh;
    background: rgba(241, 245, 251, 1);
    display: flex;
    flex-direction: column;

    .scroll {
        width: 100%;
        flex: 1;
        background: rgba(241, 245, 251, 1);
    }
}
</style>